home *** CD-ROM | disk | FTP | other *** search
- Path: crl.crl.com!not-for-mail
- From: bobfry@crl.com (Robert Fry)
- Newsgroups: comp.lang.c
- Subject: Re: do || die;
- Date: 7 Mar 1996 09:59:46 -0800
- Organization: CRL Dialup Internet Access
- Message-ID: <4hn86i$rpm@crl.crl.com>
- References: <1996Mar7.052636.59812@ucl.ac.uk>
- NNTP-Posting-Host: crl.com
-
- slidel@bsm.bioc.ucl.ac.uk (Timothy Slidel) writes:
-
- >Whilst it seems to work ok - is it considered bad style to use
- >logical operator expressions as conditional statements on their own, a la
- >Perl?
-
- >e.g. if I want to decrement i only when it is != 0:
-
- >i && i--;
-
- I would consider it very poor style, especially when the more common
- alternative:
-
- if (i) i--;
-
- takes all of two more characters to type, is more clear to a stranger
- coming upon the code (or yourself, maintaining it), and runs exactly as
- fast and should compile to the same size, as well.
-
- In general, I avoid the use of idiosyncratic constructs like the one you
- suggest, except when there is some definite advantage to them.
- Gratuitous use of anything like the above is something I find to be
- a prime cause of maintenance headaches, and so a poor idea. If I find I
- have a real need for something (such as the old XOR-based trick for
- swapping values), I document it heavily and note any limitations
- prominently. Assuming I can spot them -- such things often have
- non-obvious drawbacks that can cause troubles.
-
- Bob
-